package com.yanzq;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ResponseController {
    /**
     * 响应
     * @param response
     * @throws Exception
     */
    @RequestMapping("/request")
    public void Response(HttpServletResponse response) throws Exception{
//        设置响应码
        response.setStatus(200);
//        设置响应头
        response.setHeader("name", "yanzq");
//        设置响应体
        response.getWriter().write("<h1>hello world</h1>");

    }
    @RequestMapping("/response2")
    public ResponseEntity<String> response2(HttpServletResponse response){
        return ResponseEntity.status(200).header("name", "yanzhengqi").body("<h1>nihao</h1>");
    }
}
